package best.driver.android.Activity.Register;


import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.*;
import best.driver.android.Activity.Base.BaseActivity;
import best.driver.android.Activity.Order.Adapter.CarItemAdapter;
import best.driver.android.Activity.Order.Adapter.OrderItemAdapter;
import best.driver.android.Beans.CarItemInfo;
import best.driver.android.Beans.OrderListItemInfo;
import best.driver.android.Event.NewOrderAcceptedEvent;
import best.driver.android.Event.SelectCarEvent;
import best.driver.android.R;
import best.driver.android.RequestFactory;
import best.driver.android.View.BasePullToRefreshListView;
import best.driver.android.common.app.AppProxyFactory;
import best.driver.android.common.network.ApiArrayRequest;
import best.driver.android.common.network.ApiRequest;
import best.driver.android.common.network.BestError;
import butterknife.ButterKnife;
import butterknife.InjectView;
import butterknife.OnClick;
import de.greenrobot.event.EventBus;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

public class SelectCarActivity extends BaseActivity implements BasePullToRefreshListView.OnPullDownListener {

    @InjectView(R.id.prv_order_list)
    BasePullToRefreshListView mPrvCar;

    CarItemAdapter mAdapter;

    List<CarItemInfo> mItems = new ArrayList<CarItemInfo>();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setView(R.layout.activity_order_list);
        ButterKnife.inject(this, view);
        mPrvCar.setOnPullDownListener(this);
        mAdapter = new CarItemAdapter(this);
        mPrvCar.setAdapter(mAdapter);
        mAdapter.setData(mItems);
        mPrvCar.setRefreshEnabled(false);
        setLeftIvBak(R.drawable.icon_navibar_back);
        getCarList("1");
        setTopTopic("车型选择");
    }



    @Override
    protected void onBack() {
        this.finish();
    }

    @Override
    public void onRefresh() {

    }

    @Override
    public void onMore() {

    }

    private void getCarList(String cityId) {
        showWaiting();
        ApiArrayRequest<CarItemInfo> request = RequestFactory.createGetCarListRequest(cityId);
        request.setListener(new ApiRequest.ApiRequestListener<ArrayList<CarItemInfo>>() {
            @Override
            public void onRequestSuccess(ArrayList<CarItemInfo> response) {
                hideWaiting();
                if(response != null) {
                    mItems.addAll(response);
                    mAdapter.setData(mItems);
                }
            }

            @Override
            public void onRequestError(BestError error) {
                hideWaiting();
            }
        });
        AppProxyFactory.getProxy().getNetworkManager().enqueueRequest(request);
    }

}
